package com.mileoresko.hsm.test;

import junit.framework.TestCase;

import com.mileoresko.hsm.test.machines.seminar.Course;
import com.mileoresko.hsm.test.machines.seminar.Enrollment;
import com.mileoresko.hsm.test.machines.seminar.Student;
import com.mileoresko.hsm.test.machines.seminar.Course.CourseEnrollmentState;
import com.mileoresko.hsm.test.machines.seminar.Course.CourseEvents;
import com.mileoresko.hsm.test.machines.seminar.Enrollment.EnrollmentEvents;

public class HSMTestCourse extends TestCase {

    private static final int MAX_GROUP_SIZE = 100;
    private static final int MAX_WAITING_LIST_SIZE = 20;

    private static final String COURSE_NAME = "History Matters, by Pine Apple";
    
    public void testOneCourse() {
        Course course = new Course(COURSE_NAME, MAX_GROUP_SIZE, MAX_WAITING_LIST_SIZE);
        course.start(null);

        course.pushEvent(EnrollmentEvents.SCHEDULE, "October 11th, 2011");
        course.pushEvent(EnrollmentEvents.OPEN, null);
        assertEquals(course.states().ENROLLMENT, course.getCurrentState());

        Enrollment nestedEnrollment = ((CourseEnrollmentState) course.getCurrentState()).getNestedEnrollmentHsm();
        assertEquals(nestedEnrollment.states().OPEN_FOR_ENROLLMENT, nestedEnrollment.getCurrentState());

        course.pushEvent(EnrollmentEvents.ENROLL_STUDENT, new Student("Mr. Coal Mine"));
        assertEquals(nestedEnrollment.states().OPEN_FOR_ENROLLMENT, nestedEnrollment.getCurrentState());
        
        course.pushEvent(CourseEvents.TERM_START, null);
        assertEquals(nestedEnrollment.states().CLOSED_FOR_ENROLLMENT, nestedEnrollment.getCurrentState());
        assertEquals(course.states().LECTURES, course.getCurrentState());
        
        course.pushEvent(CourseEvents.LECTURES_OVER, null);
        assertEquals(course.states().FINAL_EXAMS, course.getCurrentState());
        
        course.pushEvent(CourseEvents.EXAMS_OVER, null);
        assertEquals(course.states().COMPLETE, course.getCurrentState());
        
        course.halt(null);
    }
    
}
